package com.pet.server.ext.util.meituan;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import com.pet.server.ext.util.HttpClientUtils;
import com.pet.server.ext.util.StringUtil;

public class MeiTuanApi {

	
	/**
	 * http://api.union.meituan.com/data/api?city=%E5%8C%97%E4%BA%AC&category=%E5%AE%A0%E7%89%A9&limit=10&district_name=%E6%9C%9D%E9%98%B3%E5%8C%BA&key=bd6d205adc2886424155cdd59b544d25187&keyword=%E5%AE%A0%E7%89%A9&sort=1
	 * */
	
	public static String callMeiTuanByCity(String city,String dict,String category,Integer limit,String keyword,Integer offset){
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("city", encode(StringUtil.dealNull(city)));
		map.put("category", encode("宠物"));
		map.put("limit", StringUtil.dealNull(limit));
		map.put("district_name", encode(StringUtil.dealNull(dict)));
		map.put("key", "bd6d205adc2886424155cdd59b544d25187");
		map.put("keyword", encode("宠物"));
		map.put("sort", "1");
		String strs = HttpClientUtils.readFromURL("http://api.union.meituan.com/data/api", map, null);
		return strs;
	}
	public static String callMeiTuanByDili(Double latitude,Double longitude,String category,Integer limit,String keyword,Integer offset,Integer radius){
		Map<String, String> map = new HashMap<String, String>();
		map.put("category", encode(StringUtil.dealNull(category,"宠物")));
		map.put("lat", StringUtil.dealNull(latitude));
		map.put("lon", StringUtil.dealNull(longitude));
		map.put("radius", StringUtil.dealNull(radius));
		map.put("limit", StringUtil.dealNull(limit));
		map.put("key", "bd6d205adc2886424155cdd59b544d25187");
		map.put("keyword", encode(StringUtil.dealNull(keyword,"宠物")));
		map.put("sort", "4");
		map.put("offset", StringUtil.dealNull(offset));
		String strs = HttpClientUtils.readFromURL("http://api.union.meituan.com/data/api", map, null);
		return strs;
	}
	
	public static String encode(String src){
		try {
			return URLEncoder.encode(src, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return "";
		}
	}
	
}
